﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace mOceanWindows
{
    internal partial class frmVideo : Form
    {
        protected IntPtr _hwndParent = IntPtr.Zero;
        internal AdViewControl _control = null;
        internal String _strFile, _strUrl, _strReference;

        public frmVideo()
        {
            InitializeComponent();
        }

        internal Rectangle GetAppRect()
        {
            return AdViewControl.GetAppRect(_hwndParent);
        }

        public void SetParent(IntPtr hwnd)
        {
            _hwndParent = hwnd;
        }

        public void ShowVideo()
        {
            axWindowsMediaPlayer.settings.playCount = 10000;
            axWindowsMediaPlayer.URL = _strFile;
        }

        internal new void Move()
        {
            Rectangle rcPopup = GetAppRect();
            
            MoveWindow(Handle, rcPopup.Left, rcPopup.Top, rcPopup.Width, rcPopup.Height, false);
        }

        protected override void OnShown(EventArgs e)
        {
            Move();
            ShowVideo();
            base.OnShown(e);
        }

        [DllImport("user32.dll", SetLastError = true)]
        internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

        private void axWindowsMediaPlayer_MouseUpEvent(object sender, AxWMPLib._WMPOCXEvents_MouseUpEvent e)
        {
            Close();
            _control.Navigate( _strReference );
        }

    }
}
